import win32gui, win32print, win32con

# 获取主屏幕的缩放比
def main_screen_scale_factor():
    hDC = win32gui.GetDC(0)
    dpi1 = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
    dpi2 = win32print.GetDeviceCaps(hDC, win32con.HORZRES)
    scale_factor = dpi1 / dpi2
    print(scale_factor)

# 有问题：得到的结果不对，还是通过配置文件指定吧
def get_scale_facor(hwnd):
    wDC = win32gui.GetWindowDC(hwnd)
    dpi1 = win32print.GetDeviceCaps(wDC, win32con.DESKTOPHORZRES)
    dpi2 = win32print.GetDeviceCaps(wDC, win32con.HORZRES)
    scale_factor = dpi1 / dpi2
    print(scale_factor)

main_screen_scale_factor()

hwnd = win32gui.FindWindow("WeChatMainWndForPC", "微信")
get_scale_facor(hwnd)
